home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1994 October
/
Macformat17.cdr
/
Shareware City
/
Developers
/
shutdown-fx-20-c
/
sfx control app ƒ
/
Shell ƒ
/
menus.c
< prev
next >
Wrap
Text File
|
1994-07-11
|
8KB
|
303 lines
/**********************************************************************\
File: menus.c
Purpose: This module handles menu selections.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "graphics.h"
#include "menus.h"
#include "help.h"
#include "environment.h"
#include "error.h"
#include "file interface.h"
#include "debinhex dispatch.h"
#include "file management.h"
#include "program globals.h"
#include "sfx main window.h"
MenuHandle gAppleMenu;
MenuHandle gFileMenu;
MenuHandle gEditMenu;
MenuHandle gOptionsMenu;
enum
{
appleMenu = 400, fileMenu, editMenu, optionsMenu,
aboutItem = 1, aboutMSGItem, helpPointerItem,
openItem=1, closeItem, file_unused1, deBinHexItem, file_unused2,
quitItem,
undoItem = 1, cutItem = 3, copyItem, pasteItem, clearItem, selectAllItem,
kRestartOnly=1, kShutdownOnly, kRestartAndShutdown, kNever, kRescanForModules
};
/*-----------------------------------------------------------------------------------*/
/* internal stuff for menus.c */
void HandleAppleMenu(short menuItem);
void HandleFileMenu(short menuItem);
void HandleEditMenu(short menuItem);
void HandleHelpMenu(void);
void HandleOptionsMenu(short menuItem);
Boolean InitTheMenus(void)
{
Handle MBARHandle;
if ((MBARHandle=GetNewMBar(400))==0L) /* sez which menus are in menu bar. */
return FALSE;
SetMenuBar(MBARHandle); /* set this to be THE menu bar to use. */
if ((gAppleMenu=GetMHandle(appleMenu))==0L) /* GetNewMBar also got menu handles of */
return FALSE;
if ((gFileMenu=GetMHandle(fileMenu))==0L) /* every menu it includes, so just */
return FALSE;
if ((gEditMenu=GetMHandle(editMenu))==0L) /* grab these handles and assign them */
return FALSE;
if ((gOptionsMenu=GetMHandle(optionsMenu))==0L)
return FALSE;
AddResMenu(gAppleMenu, 'DRVR'); /* adds control panels to apple menu */
AdjustMenus(); /* dim/enable/check/mark menus/items */
DrawMenuBar(); /* draws the actual menu bar */
return TRUE;
}
void AdjustMenus(void)
{
WindowPeek theWindow;
short kind;
if (gInProgress)
{
DisableItem(gAppleMenu, aboutItem);
DisableItem(gAppleMenu, aboutMSGItem);
DisableItem(gAppleMenu, helpPointerItem);
DisableItem(gFileMenu, 0);
DisableItem(gEditMenu, 0);
DisableItem(gOptionsMenu, 0);
}
else
{
EnableItem(gAppleMenu, aboutItem);
EnableItem(gAppleMenu, aboutMSGItem);
EnableItem(gAppleMenu, helpPointerItem);
EnableItem(gFileMenu, 0);
EnableItem(gEditMenu, 0);
EnableItem(gOptionsMenu, 0);
theWindow = (WindowPeek)FrontWindow();
kind = theWindow ? theWindow->windowKind : 0;
if (kind < 0)
{
EnableItem(gEditMenu, undoItem);
EnableItem(gEditMenu, cutItem);
EnableItem(gEditMenu, copyItem);
EnableItem(gEditMenu, pasteItem);
EnableItem(gEditMenu, clearItem);
}
else
{
DisableItem(gEditMenu, undoItem);
DisableItem(gEditMenu, cutItem);
DisableItem(gEditMenu, copyItem);
DisableItem(gEditMenu, pasteItem);
DisableItem(gEditMenu, clearItem);
}
if(theWindow)
EnableItem(gFileMenu, closeItem);
else
DisableItem(gFileMenu, closeItem);
if (GetIndWindowGrafPtr(kMainWindow))
DisableItem(gFileMenu, openItem);
else
EnableItem(gFileMenu, openItem);
}
SetItemMark(gOptionsMenu, kRestartOnly, (gOnRestart && !gOnShutdown) ? '◊' : noMark);
SetItemMark(gOptionsMenu, kShutdownOnly, (!gOnRestart && gOnShutdown) ? '◊' : noMark);
SetItemMark(gOptionsMenu, kRestartAndShutdown, (gOnRestart && gOnShutdown) ? '◊' : noMark);
SetItemMark(gOptionsMenu, kNever, (!gOnRestart && !gOnShutdown) ? '◊' : noMark);
}
void HandleMenu(long mSelect)
{
short menuID = HiWord(mSelect);
short menuItem = LoWord(mSelect);
switch (menuID)
{
case appleMenu:
HandleAppleMenu(menuItem);
break;
case fileMenu:
HandleFileMenu(menuItem);
break;
case editMenu:
HandleEditMenu(menuItem);
break;
case optionsMenu:
HandleOptionsMenu(menuItem);
break;
}
}
void DoTheCloseThing(WindowPeek theWindow)
/* a standard close procedure, called when "close" is chosen from File menu and when
a window is closed through its close box */
{
Boolean gotone;
short i;
short kind;
if (theWindow==0L)
return;
kind = theWindow ? theWindow->windowKind : 0;
if (kind<0) /* DA window or other system window */
CloseDeskAcc(kind);
else
{
gotone=FALSE;
/* see if it's one of ours */
for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
gotone=((WindowPtr)theWindow==GetIndWindowGrafPtr(i));
if (gotone) /* if it's one of ours... see graphics.c */
CloseTheIndWindow(i-1); /* this may return FALSE = not closed */
else
DisposeWindow((WindowPtr)theWindow); /* not one of ours, so just close it */
AdjustMenus(); /* may affect which menu items or menus are available, etc */
}
}
void HandleAppleMenu(short menuItem)
{
GrafPtr savePort;
Str255 name;
switch (menuItem)
{
case aboutItem:
OpenTheIndWindow(kAbout);
break;
case aboutMSGItem:
OpenTheIndWindow(kAboutMSG);
break;
case helpPointerItem:
HandleHelpMenu();
break;
default:
if (menuItem > helpPointerItem+1)
{
GetPort(&savePort);
GetItem(gAppleMenu, menuItem, name);
OpenDeskAcc(name);
SetPort(savePort);
}
break;
}
}
void HandleFileMenu(short menuItem)
{
WindowPtr theWindow;
short i;
Boolean gotone;
switch (menuItem)
{
case openItem:
OpenTheIndWindow(kMainWindow);
break;
case closeItem:
DoTheCloseThing((WindowPeek)FrontWindow());
break;
case deBinHexItem:
if (GetSourceFile(&inputFS, TRUE, FALSE))
{
SetErrorParameters("\pFile: ", inputFS.name, "\p");
HandleError(DeBinHexDispatch(), FALSE, TRUE);
}
break;
case quitItem:
gDone = TRUE;
break;
}
}
void HandleEditMenu(short menuItem)
{
if (gFrontWindowIsOurs)
{
switch (menuItem)
{
case undoItem: CallIndDispatchProc(gFrontWindowIndex, kUndo, 0L); break;
case cutItem: CallIndDispatchProc(gFrontWindowIndex, kCut, 0L); break;
case copyItem: CallIndDispatchProc(gFrontWindowIndex, kCopy, 0L); break;
case pasteItem: CallIndDispatchProc(gFrontWindowIndex, kPaste, 0L); break;
case clearItem: CallIndDispatchProc(gFrontWindowIndex, kClear, 0L); break;
case selectAllItem: CallIndDispatchProc(gFrontWindowIndex, kSelectAll, 0L); break;
}
}
else SystemEdit(menuItem-1);
}
void HandleHelpMenu(void)
{
OpenTheIndWindow(kHelp);
}
void HandleOptionsMenu(short menuItem)
{
switch (menuItem)
{
case kRestartOnly:
gOnRestart=TRUE;
gOnShutdown=FALSE;
break;
case kShutdownOnly:
gOnRestart=FALSE;
gOnShutdown=TRUE;
break;
case kRestartAndShutdown:
gOnRestart=gOnShutdown=TRUE;
break;
case kNever:
gOnRestart=gOnShutdown=FALSE;
break;
case kRescanForModules:
if (!GetIndWindowGrafPtr(kMainWindow))
OpenTheIndWindow(kMainWindow);
else
HandleError(MakeNewLists(TRUE), TRUE, FALSE);
break;
}
}